package noobteam.deartrainer.mapper;


import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 徐紫印
 */
@Mapper
public interface BudgetInfoMapper {

    /**
     * 插入交易记录
     * @param budget 交易内容，包括userid、金额、类型
     * @return 返回操作是否完成
     */
    @Insert("INSERT INTO budgetinfo (userId, itemType, itemDateTime, itemMoney, currentUseBalance) " +
            "VALUES (#{budget.userId}, #{budget.itemType}, #{budget.itemDateTime}, #{budget.itemMoney}, " +
            "#{budget.currentUseBalance})")
    public boolean createBudget(@Param("budget") Map<String, Object> budget);

    /**
     * 获取该用户的所有消费记录
     */
    @Select("SELECT * FROM budgetinfo WHERE userId = #{userId} ORDER BY itemDateTime DESC")
    public List<Map<String, Object>> getBudgetInfoById(@Param("userId") Integer userId);
}
